package com.app.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

/**
 * 2015-11-9
 * 点滴云
 * lbh
 * @author lblbh
 *
 */
public class RatioLinearLayoutView extends RelativeLayout {

	private float ratio = 0f;

	public RatioLinearLayoutView(Context context, AttributeSet attrs) {
		super(context, attrs);

		ratio = attrs.getAttributeFloatValue("http://schemas.android.com/apk/res-auto"
				, "linear_bl", 0f);
	}


	public RatioLinearLayoutView(Context context) {
		super(context);
	}
	

	public void setRatio(float ratio){
		this.ratio = ratio;
	}

	public float getRatio(){
		return ratio;
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int width = MeasureSpec.getSize(widthMeasureSpec);
		if(ratio!=0){
			float height = width / ratio;
			heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) height,MeasureSpec.EXACTLY);
		}
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}
}
